package com.example.administrator.yuejian23.Fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian23.Bean.MyOrder;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.R;
import com.example.administrator.yuejian23.Retrofit.RetrofitService;
import com.example.administrator.yuejian23.adapter.UserOrderAdapter;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class AllOrderFragment extends Fragment {
    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private UserOrderAdapter userOrderAdapter;
    private List<MyOrder> myOrderList;
    private String User_Id;
    String id;
    private Context context;
    private int user_id;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.activity_all_order_fragment,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.allorder_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        /*  User_Id=getIntent().getStringExtra("User_Id");*/
        final String userid = "97";
     /*   userid = getActivity().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getInt("user_id",0);
        Log.v("获取id++++++++++", String.valueOf(userid));*/
        retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetrofitService services = retrofit.create(RetrofitService.class);
        retrofit2.Call<List<MyOrder>> call = services.getUserOrder(user_id);

        call.enqueue(new Callback<List<MyOrder>>() {
            @Override
            public void onResponse(Call<List<MyOrder>> call, Response<List<MyOrder>> response) {
                List<MyOrder> list = response.body();
                recyclerView.setAdapter(new UserOrderAdapter(getActivity(),list));
            }
            @Override
            public void onFailure(Call<List<MyOrder>> call, Throwable t) {
               /* Toast.makeText(MyOrderActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();*/
            }
        });
        return view;
    }
}